package com.hs.Lotto;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.StringTokenizer;

import com.hs.Log.DebugPrint;

public class LottoParser
{
	private final String LOG_TAG = "LottoParser";
	
	private String m_strOrgData = "";
	private HashMap<String,String> m_hash;
	
	public LottoParser()
	{
	}
	
	public void setData( String _strOrg )
	{
		m_strOrgData = _strOrg; 
	}
	
	public synchronized void parse()
	{
		// [{ GRWNO : "457", GRWDate : "2011-09-03", FirstBall	: "8", SecondBall	: "10", ThirdBall	: "18", 
		// FourthBall	: "23", FifthBall	: "27", SixthBall	: "40", BonusBall	: "33" }]
		
		//[{ GRWNO : "457", FirstBall : "08", SecondBall : "10", ThirdBall : "18", FourthBall : "23", FifthBall : "27",
		//SixthBall : "40", BonusBall : "33", GRWDate : "2011.09.03", FirstPrzwnerCo : "10", FirstWinamnt : "1159902825", 
		//TotFirstWinamnt : "11599028250", SecondPrzwnerCo : "47", SecondWinamnt : "41131306", TotSecondWinamnt : "1933171382", 
		//ThirdPrzwnerCo : "1506", ThirdWinamnt : "1283647", TotThirdWinamnt : "1933172382", ForthPrzwnerCo : "72524", 
		//ForthWinamnt : "50000", TotForthWinamnt : "3626200000", FifthPrzwnerCo : "1149591", FifthWinamnt : "5000", 
		//TotFifthWinamnt : "362620000", TotPrzwnerCo : "1223678", TotPrzamnt : "24839526000", TotSellamnt : "49679052000", 
		//CarryOn : "", FirstPrz : "10", FirstAmt : "1,159,902,825", curDRWNO : "457", prevDRWNO : "456", nextDRWNO : "0", 
		//prevFirstPrz : "7", pprevFirstPrz : "7", carryAmt : "11,599,028,250" }]
		
		if( m_hash == null )
		{
			m_hash = new HashMap<String,String>();
		} // end if( m_hash == null )
		
		char []arrChar = m_strOrgData.toCharArray();
		int nLen = arrChar.length;
		
		StringBuilder strB = new StringBuilder();
		
		for( int i = 0 ; i < nLen ; i++ )
		{
			if( arrChar[i] != '[' && arrChar[i] != ']' && arrChar[i] != '{' && arrChar[i] != '}' && arrChar[i] != ' ' && arrChar[i] != '\n' && arrChar[i] != '\"' && arrChar[i] != '\t' && arrChar[i] != '\r' )
			{
				strB.append(arrChar[i]);
			} // end if( arrChar[i] != '[' && arrChar[i] != ']' && arrChar[i] != '{' && arrChar[i] != '}' && arrChar[i] != ' ' && arrChar[i] != '\n' && arrChar[i] != '\"' )
			
		} // end for( int i = 0 ; i < nLen ; i++ )
		
		ArrayList<String> arrLst = new ArrayList<String>();
		
		StringTokenizer stnozer = new StringTokenizer(strB.toString().trim() , ",");
		
		while(stnozer.hasMoreElements())
    	{
			arrLst.add(stnozer.nextToken());
    	} // end while(stnozer.hasMoreElements())
		
		int nArrLen = arrLst.size();
		String strTmp = "";
		String[] arrStr = new String[2];
		int k =0 ;
		
		for( int j = 0 ; j < nArrLen ; j++ )
		{
			strTmp = arrLst.get(j);
			StringTokenizer st = new StringTokenizer(strTmp , ":");
			
			while(st.hasMoreElements())
	    	{
				arrStr[k] = st.nextToken();
				k++;
	    	} // end while(st.hasMoreElements())
			
			k = 0;
			
			m_hash.put(arrStr[0], arrStr[1]);
			
		} // end for( int j = 0 ; j < nArrLen ; j++ )
		
		arrLst.clear();
		arrLst = null;
		
		strB = null;
		stnozer = null;
			
	}
	
	
	public String getTurn()
	{
		return m_hash.get(LottoInfoDefines.STR_GRWNO);
	}
	
	public String getDate()
	{
		return m_hash.get(LottoInfoDefines.STR_GRWDATE);
	}
	
	public String get1stBall()
	{
		return m_hash.get(LottoInfoDefines.STR_FIRST_BALL);
	}
	
	public String get2ndBall()
	{
		return m_hash.get(LottoInfoDefines.STR_SECOND_BALL);
	}
	
	public String get3rdBall()
	{
		return m_hash.get(LottoInfoDefines.STR_THIRD_BALL);
	}
	
	public String get4thBall()
	{
		return m_hash.get(LottoInfoDefines.STR_FOURTH_BALL);
	}
	
	public String get5thBall()
	{
		return m_hash.get(LottoInfoDefines.STR_FIFTH_BALL);
	}
	
	public String get6thBall()
	{
		return m_hash.get(LottoInfoDefines.STR_SIXTH_BALL);
	}
	
	public String getBonusBall()
	{
		return m_hash.get(LottoInfoDefines.STR_BONUS_BALL);
	}
	
	public String get1stWinnerCnt()
	{
		return m_hash.get(LottoInfoDefines.STR_FIRST_PRZ_WNER_CO);
	}
	
	public String get1stWinnerMoney()
	{
		return m_hash.get(LottoInfoDefines.STR_FIRST_WIN_AMOUNT);
	}
	
	public String get2ndWinnerCnt()
	{
		return m_hash.get(LottoInfoDefines.STR_SECOND_PRZ_WNER_CO);
	}
	
	public String get2ndWinnerMoney()
	{
		return m_hash.get(LottoInfoDefines.STR_SECOND_WIN_AMOUNT);
	}
	
	public String get3rdWinnerCnt()
	{
		return m_hash.get(LottoInfoDefines.STR_THIRD_PRZ_WNER_CO);
	}
	
	public String get3rdWinnerMoney()
	{
		return m_hash.get(LottoInfoDefines.STR_THIRD_WIN_AMOUNT);
	}
	
	public String get4thWinnerCnt()
	{
		return m_hash.get(LottoInfoDefines.STR_FOURTH_PRZ_WNER_CO);
	}
	
	public String get4thWinnerMoney()
	{
		return m_hash.get(LottoInfoDefines.STR_FOURTH_WIN_AMOUNT);
	}
	
	public String get5thWinnerCnt()
	{
		return m_hash.get(LottoInfoDefines.STR_FIFTH_PRZ_WNER_CO);
	}
	
	public String get5thWinnerMoney()
	{
		return m_hash.get(LottoInfoDefines.STR_FIFTH_WIN_AMOUNT);
	}
	
	public void clear()
	{
		m_strOrgData = "";
		m_hash.clear();
	}
}
